package com.backend;

import cn.dev33.satoken.SaManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.Banner;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.core.env.Environment;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 启动类
 *
 * @author backend-manage
 */
@Slf4j
@EnableSwagger2
@EnableTransactionManagement
@EnableAspectJAutoProxy(exposeProxy = true)
@SpringBootApplication
public class BackendManageSystemApplication implements CommandLineRunner {

    public static void main(String[] args) throws UnknownHostException {
        final ConfigurableApplicationContext applicationContext = new SpringApplicationBuilder(BackendManageSystemApplication.class)
                .bannerMode(Banner.Mode.OFF)
                .run(args);

        Environment env = applicationContext.getEnvironment();
        String contextPath = env.getProperty("server.servlet.context-path");
        log.info("\n----------------------------------------------------------\n" +
                        "\tApplication '{}' is running! Access URLs:\n" +
                        "\tLocal: \t\thttp://localhost:{}{}\n" +
                        "\tExternal: \thttp://{}:{}{}\n" +
                        "\tDoc: \thttp://{}:{}{}/doc.html\n" +
                        "\t----------------------------------------------------------\n",
                env.getProperty("spring.application.name"),
                env.getProperty("server.port"), contextPath,
                InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"), contextPath,
                InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"), contextPath);
    }

    @Override
    public void run(String... args) throws Exception {
        log.info("启动成功，Sa-Token 配置如下：{}", SaManager.getConfig());
    }
}
